/**
 * User: alesj
 * Date: 2004.8.23
 * Time: 16:20:57
 */

package com.generalynx.common.web.tags;

import com.generalynx.common.constants.WebConst;
import com.generalynx.common.web.module.UserModules;
import org.apache.struts.taglib.tiles.util.TagUtils;
import org.apache.struts.util.RequestUtils;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class ModuleSetTag extends TagSupport {

    private int m_level;
    private String m_name;
    private String m_scope = "page";

    public int getLevel() {
        return m_level;
    }

    public void setLevel(int level) {
        m_level = level;
    }

    public String getName() {
        return m_name;
    }

    public void setName(String name) {
        m_name = name;
    }

    public String getScope() {
        return m_scope;
    }

    public void setScope(String scope) {
        m_scope = scope;
    }

    public int doStartTag() throws JspException {
        if (m_name == null)
            throw new JspException("Module name cannot be null!");

        UserModules userModules = (UserModules)RequestUtils.lookup(pageContext,
                                                                   WebConst.USER_MODULES,
                                                                   "request");

        TagUtils.setAttribute(pageContext, m_name, userModules.getModule(getLevel()), m_scope);

        return TagSupport.EVAL_PAGE;
    }

}
